<?php
namespace app\home\controller;

use app\common\model\ViewBlock;
use app\common\model\ViewBlockContent;
use think\Controller;

class Index extends Controller
{
	public function _initialize() {
		$view=new ViewBlock();
		$links=$view->getContentByPosition("youqinglianjie");
		$this->assign('links',$links);
	}
	
	public function index()
    {
    	$view=new ViewBlock();
    	$data['banner']=$view->getContentByPosition("shouyebanner");
	    $data['desc']=$view->getContentByPosition("jianjie");
	    $data['desc']['content'][0]['content']=mb_substr($data['desc']['content'][0]['content'],0,500, 'utf-8').'...';
	    $data['media']=$view->getContentByPosition("xuanchuanpian");
	    $data['pics']=$view->getContentByPosition("tuji");
	    //两列显示报道
	    $ad_list=$view->getContentByPosition("baodao");
	    $offset=ceil(count($ad_list['content'])/2);
	    if($offset<6){
		    $offset=6;
	    }
	    $ad_1_list=[];
	    $ad_2_list=[];
	    foreach ( $ad_list['content'] as $key=>$item ) {
	    	if($key<12){
			    if($key<$offset){
				    array_push($ad_1_list,$item);
			    }else{
				    array_push($ad_2_list,$item);
			    }
		    }
		    
	    }
	    $data['ad_1_list']=$ad_1_list;
	    $data['ad_2_list']=$ad_2_list;
	    
	    $data['pro_list']=$view->getContentByPosition("zanzhushang");
	    $data['sponsor']=$data['pro_list']['content'][0];
	    $data['jb_list']=$view->getContentByPosition("jiabin");
	    foreach ($data['jb_list']['content'] as &$item){
	    	$item['sub_content']=mb_substr($item['content'],0,50, 'utf-8').'...';
	    }
	    //显示评委
	    $pw_list=$view->getContentByPosition("pingwei");
	    $pw_1_list=[];
	    foreach ( $pw_list['content'] as $key=>&$item ) {
		    $item['sub_content']=mb_substr($item['content'],0,50, 'utf-8').'...';
		    array_push($pw_1_list,$item);
	    }
	    $data['pw_1_list']=$pw_1_list;
	    
	    $data['pics_dinner']=$view->getContentByPosition("wanyan");
	    $data['media_list']=$view->getContentByPosition("jingcaishipin");
	    $data['history']=$view->getContentByPosition("wangqi");
	    foreach ($data['history']['content'] as &$item){
		    $item['sub_content']=mb_substr($item['content'],0,25, 'utf-8');
	    }
    	return $this->fetch('',$data);
    }
    public function contentDetail(){
	    $view=new ViewBlockContent();
	    $data['info']=$view->getInfo(['id'=>input('id')]);
	    return $this->fetch('',$data);
    }
    public function photos(){
	    $view=new ViewBlock();
	    $data['list']=$view->getContentByPosition("tuji");
	    return $this->fetch('',$data);
    }
    public function news(){
	    $view=new ViewBlock();
	    $data['list']=$view->getContentByPosition("baodao");
	    return $this->fetch('',$data);
    }
    public function register(){
	    $view=new ViewBlock();
	    $data['group_list']=$view->getContentByPosition("zubie")['content'];
	    $data['submit_url']=url("api/index/register");
	    return $this->fetch('',$data);
    }
}
